﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

namespace LabMS.Web.Equipment.LowValue
{
    public partial class lowrecipients : Base.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            tbRecipientsDate.Attributes.Add("onclick", "c.showMoreDay = false;c.show(this);");
            
            strPagePrivilege.Add("DZPLY");//必须写在ispostback外
            strPageUserType.Add("mana");
            if (!Page.IsPostBack)
            {
                bind();
                tbCNub.Attributes.Add("readOnly", "-1");
                tbRPersion.Attributes.Add("readOnly", "-1");
                tbRecipientsDate.Attributes.Add("readOnly", "-1");
                lbCName.Attributes.Add("readOnly", "-1");
            }
        }

        public void bind()
        {
            tbRecipientsDate.Text = DateTime.Now.Date.ToShortDateString();
        }

        protected void Submit_Click(object sender, EventArgs e)
        {

            #region 验证
            if (string.IsNullOrEmpty(tbCNub.Text.Trim()))
            {
                LabMS.Common.JShelper.JSAlert(Page, "err", "仪器编号不能为空!");
                return;
            }


            if (string.IsNullOrEmpty(tbRPersion.Text.Trim()))
            {
                LabMS.Common.JShelper.JSAlert(Page, "err", "领用人不能为空!");
                return;
            }
            if (string.IsNullOrEmpty(tbRecipientsDate.Text.Trim()))
            {
                LabMS.Common.JShelper.JSAlert(Page, "err", "领用时间不能为空!");
                return;
            }

            #endregion

            ExtendBLL.Recipients brecipients = new ExtendBLL.Recipients();
            Model.Recipients recipients = new LabMS.Model.Recipients();
            recipients.Comment = tbRemarks.Text;
            recipients.Name = lbCName.Text.Trim();
            recipients.Numbers = tbCNub.Text.Trim();
            recipients.Type = "lowvalue";
            recipients.MRecipients = tbRPersion.Text.Trim();
            try
            {
                DateTime temp = DateTime.Parse(tbRecipientsDate.Text.Trim());
                recipients.EncodedTime = temp;
            }
            catch { }
            recipients.BorrowedState = tbBorrowstatus.Text.Trim();
            recipients.Operator = tbOperator.Text.Trim();
            try
            {
                DateTime temp = DateTime.Parse(tbRecipientsDate.Text.Trim());
                recipients.OperatDate = temp;
            }
            catch { }
            try
            {
                brecipients.ExtendAdd(recipients);

            }
            catch (Exception ex)
            {
                lbErr.Visible = true;
                lbErr.Text = ex.Message.ToString();
                return;
            }
            LabMS.Common.JShelper.JSAlertAndRedirect(Page, "AddSuccess", "领用成功!", "lowrecipients.aspx");
        }

    }
}
